package com.genesis.yunnanji.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.genesis.yunnanji.R;
import com.genesis.yunnanji.adapter.TabAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/11/3.
 */
public class Strategy extends Fragment {
    private TabLayout mTablayout;
    private ViewPager mViewPager;
    private TabAdapter adapter;
    public String[] tabTitle;
    private View view;

    public static Strategy newInstance(String param) {
        Strategy obj = new Strategy();
        Bundle bundle = new Bundle();
        bundle.putString("args1", param);
        obj.setArguments(bundle);
        return obj;
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (view == null) {
            view = this.getActivity().getLayoutInflater().inflate(R.layout.fragment_strategy, null);
            mViewPager = (ViewPager) view.findViewById(R.id.vp_strategy_viewpager);
            mTablayout = (TabLayout) view.findViewById(R.id.tl_strategy_tab);
            setUpView();
        } else {
            ViewGroup parent = (ViewGroup) view.getParent();
            if (parent != null) {
                parent.removeView(view);
            }
        }
        return view;
    }

    protected void initView() {

    }

    protected void setUpView() {
        tabTitle = new String[]{"特色体验", "菌类体验", "非遗体验"};
        mTablayout.setTabMode(TabLayout.MODE_FIXED);
        mTablayout.setTabGravity(TabLayout.GRAVITY_FILL);
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(SpecialtyStrategy.newInstance("特色体验"));
        fragments.add(RushroomStrategy.newInstance("菌类体验"));
        fragments.add(HeritageStrategy.newInstance("非遗体验"));
        adapter = new TabAdapter(getActivity().getSupportFragmentManager(), fragments, tabTitle);
        mViewPager.setAdapter(adapter);
        mTablayout.setupWithViewPager(mViewPager);
    }
}
